package com.jjc.android.activity

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.widget.TextView
import com.hjq.toast.ToastUtils
import com.jjc.android.Constants
import com.jjc.android.R
import com.jjc.android.base.BaseActivity
import com.jjc.android.dialog.InputTextDialog
import com.jjc.android.entity.LzyResponse
import com.jjc.android.net.SimpleHttpCallback
import com.jjc.android.util.Common
import com.jjc.android.util.paramEx
import com.jjc.android.view.onClick
import com.lxj.xpopup.XPopup
import com.lzy.okgo.OkGo
import java.util.Date

class InspectionVersionActivity : BaseActivity() {

    override val layoutId: Int = R.layout.activity_inspection_version
    private val uploadExceptionBtn: TextView by lazy { findViewById<TextView>(R.id.uploadExceptionBtn) }
    private val takePhotoBtn: TextView by lazy { findViewById<TextView>(R.id.takePhotoBtn) }
    private val camera2Btn: TextView by lazy { findViewById<TextView>(R.id.camera2Btn) }
    override fun initView(savedInstanceState: Bundle?) {
        takePhotoBtn.setOnClickListener {
            CameraActivity.start(this)
        }
        camera2Btn.setOnClickListener {
            startActivity(Intent(this,ProbeActivity::class.java))
        }
        uploadExceptionBtn.onClick {
            XPopup.Builder(this)
                .isDestroyOnDismiss(true)
                .asCustom(InputTextDialog(this){ code->
                    submitReport(code)
                })
                .show()
        }

    }



    private fun submitReport( code:String?){
        OkGo.post<LzyResponse<String>>(Constants.reportEx)
            .paramEx(mutableMapOf(
                "phoneModel" to Build.MODEL,
                "systemVersion" to Build.VERSION.RELEASE,
                "mobileBrand" to Build.BRAND,
                "exCondition" to code,
                "reportTime" to Common.sdf.format(Date())))
            .tag(this)
            .execute(object : SimpleHttpCallback<LzyResponse<String>>(activity = this){
                override fun onCallSuccess(response: LzyResponse<String>) {
                    ToastUtils.show("上报成功")

                }

                override fun onCallError(error: String?) {
                    super.onCallError(error)
                    ToastUtils.show("上报失败：$error")
                }
            })
    }
}